import {Injectable, Inject} from '@angular/core';
import {DOCUMENT} from "@angular/platform-browser";
import * as globals from '@core/globals/globals.service';
@Injectable()
export class ToolbarService {
  constructor(@Inject(DOCUMENT) public document: any) {
  }


  showNav(): void {
    const firstTime = localStorage.getItem('firstTime');
    if (!firstTime) {
      let timer;
      timer = setTimeout(() => {
        if (!document.body.classList.contains('unfold')) {
          this.document.body.classList.add('unfold');
          window.clearTimeout(timer);
          localStorage.setItem('firstTime', 'true');
        }
        let time;
        time = setTimeout(() => {
          this.document.body.classList.remove('unfold');
          window.clearTimeout(time);
        }, 3000);
      }, 3000);
    }
  }


  unfoldNav(status: boolean = false): void {
    if (!!status) {
      if (!document.body.classList.contains('unfold')) {
        globals.isUnfold.next(true);
        this.document.body.classList.add('unfold');
      }
    } else {
      if (document.body.classList.contains('unfold')) {
        globals.isUnfold.next(false);
        this.document.body.classList.remove('unfold');
      }
    }
  }


}
